<?php

/*
* @Author: 李明
* @Date: 2021-07-24 15:33:05
 * @LastEditors: 李明
 * @LastEditTime: 2021-11-30 18:03:14
* @Description:
 * @FilePath: /CRM2.0-PHP/app/Http/Controllers/common/LMReturn.php
*/

namespace App\Http\Controllers\common;

class LMReturn
{
    /**
     * @description: 数据库查询结果返回
     * @param $msgSuc
     * @return {*}
     */
    public static function sqlRes($isSuc, $msgSuc = '成功', $msgErr = '失败', $data = [], $ErrCode = '707')
    {
        if ($isSuc) {
            $code = '200';
            $msg = $msgSuc;
        } else {
            $code = $ErrCode;
            $msg = $msgErr;
        }
        $dic = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
        return json_encode($dic, JSON_UNESCAPED_UNICODE);
    }
    static function tokenErr($msg = 'token无效', $code = '400', $data = [])
    {
        $dic = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
        return json_encode($dic, JSON_UNESCAPED_UNICODE);
    }
    static function updateErr($msg = '修改失败', $code = '7071', $data = [])
    {
        $dic = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
        // dd($dic);
        return json_encode($dic, JSON_UNESCAPED_UNICODE);
    }
    static function insertErr($msg = '添加失败', $code = '7072', $data = [])
    {
        $dic = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
        return json_encode($dic, JSON_UNESCAPED_UNICODE);
    }
    static function deleteErr($msg = '删除失败', $code = '7073', $data = [])
    {
        $dic = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
        return json_encode($dic, JSON_UNESCAPED_UNICODE);
    }
    static function selectErr($msg = '查询失败', $code = '7074', $data = [])
    {
        $dic = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
        return json_encode($dic, JSON_UNESCAPED_UNICODE);
    }
    static function Success($data = [], $msg = '成功', $code = '200')
    {
        $dic = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];
        return json_encode($dic, JSON_UNESCAPED_UNICODE);
    }
    static function Error($msg = '发生错误，请联系管理员', $code = '300', $data = [])
    {
        if ($code == 400) {
            $msg = 'token无效';
        }
        $dic = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ];

        return json_encode($dic, JSON_UNESCAPED_UNICODE);
    }
}
